<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------

namespace app\supplier\controller;
use think\Controller;
use think\Session;

class Base extends Controller
{
	/**
     * 初始化
     * @author 郑义生 <1052063941@qq.com>
     * @return mixed
     */
	public function _initialize()
    {
        // 获取当前模块名称
        $module = '';
        $dispatch = request()->dispatch();
        if (isset($dispatch['module'])) {
            $module = $dispatch['module'][0];
        }
        // 获取入口目录
        $base_file = request()->baseFile();
        $base_dir  = substr($base_file, 0, strripos($base_file, '/') + 1);
        define('PUBLIC_PATH', $base_dir);
		define('MOUBLE_NAME', $module);
		define('TOKEN', md5('admin.index.user'));
		// 视图输出字符串内容替换
        $PUBLIC_STATIC_SRC = [
            // 静态资源目录
            '__STATIC__'    => PUBLIC_PATH. 'static/supplier',
            // 文件上传目录
            '__UPLOADS__'   => PUBLIC_PATH. 'uploads',
            // 前台CSS目录
            '__Home_CSS__' => PUBLIC_PATH. 'static/supplier/css',
            // 前台JS目录
            '__Home_JS__'  => PUBLIC_PATH. 'static/supplier/js',
            // 前台IMG目录
            '__Home_IMG__' => PUBLIC_PATH. 'static/supplier/images',
        ];
		$this->assign('MOUBLE_NAME',$module);
		$this->assign('PUBLIC_STATIC_SRC',$PUBLIC_STATIC_SRC);
		$controller = Request()->controller();
		$action = Request()->action();
		if(empty(Session::get('supplier_id'))){
			if(($controller=='User' && $action=='login') || ($controller=='User' && $action=='loging') || ($controller=='User' && $action=='logout')){
				
			}else{
				$this->success('请先登录', '/'.$module.'/user/login');
			}
		}
    }
}
